package fem3d;

import fem2.AbstractStructuralDynamicsDemo;
import fem2.Element;
import fem2.MaterialModel;
import fem2.MeshPart;
import fem2.Model;
import fem2.analysis.Analysis;
import fem2.analysis.FreeVibrationAnalysis;
import fem2.element.NonlinearStructuralElement;
import fem2.enu.EchoLevelType;
import fem2.enu.MassMatrixType;
import fem2.enu.NewmarkType;
import fem2.enu.State;
import fem2.material.StVenantKirchhoffMM;
import fem2.strategies.Strategy;

/**
 * @author hbui
 * 
 */
public class Beam3dNonlinearFreeVibration extends Beam3dFreeVibration {

	public Beam3dNonlinearFreeVibration() {
		// meshFileName = "mesh2-dynamics.msh"; // tetrahedra mesh
		meshFileName = "mesh1-dynamics-Newmark-nonlinear.msh"; // structured
																// hexahedra
		// mesh
		// meshFileName = "mesh1-dynamics-NewmarkCrisfield.msh"; // structured
		// hexahedra
		// mesh
	}

	@Override
	public Analysis createAnalysis(Model m) {
		Analysis an = new FreeVibrationAnalysis(m, MassMatrixType.VARIATIONAL_MASS_LUMPING, 0.0,
				0.0); // no damping

		// ((FreeVibrationAnalysis)
		// an).setAnalysisTypeToNonAdaptiveNewmark(NewmarkType.NewmarkAlpha,
		// 0.8, 0.0, 1e-3, 200);

		((FreeVibrationAnalysis) an).setAnalysisTypeToNonAdaptiveNewmarkCrisfieldFormulation(
				NewmarkType.NewmarkAlpha, 0.8, 0.0, 1e-3, 200);

		// ((FreeVibrationAnalysis) an).setAnalysisTypeToCDM(0, 1e-5, 2000);

		Strategy s = an.getStrategy();
		s.setEchoLevel(EchoLevelType.OUTPUT);
		return an;
	}

	@Override
	public MaterialModel createMaterial(Model m) {
		double E = 25850 * 10e6;
		double nu = 0.18;
		double rho = 7850;
		double t = 1.0;
		State ss = State.THREE_DIMENSIONAL;
		return new StVenantKirchhoffMM(E, nu, t, rho, ss);
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm) {
		return new NonlinearStructuralElement(mp, mm);
	}

	public static void main(String[] args) {
		AbstractStructuralDynamicsDemo demo = new Beam3dNonlinearFreeVibration();

		demo.run();
	}
}
